package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysAssetTransferVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAssetTransfer;
import com.ruoyi.system.service.ISysAssetTransferService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产调拨Controller
 * 
 * @author sxy
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/transfer")
public class SysAssetTransferController extends BaseController
{
    @Autowired
    private ISysAssetTransferService sysAssetTransferService;

    /**
     * 查询资产调拨列表
     */
    @RequiresPermissions("system:transfer:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAssetTransfer sysAssetTransfer)
    {
        startPage();
        List<SysAssetTransferVo> list = sysAssetTransferService.selectSysAssetTransferList(sysAssetTransfer);
        return getDataTable(list);
    }

    /**
     * 导出资产调拨列表
     */
    @RequiresPermissions("system:transfer:export")
    @Log(title = "资产调拨", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAssetTransfer sysAssetTransfer)
    {
        List<SysAssetTransferVo> list = sysAssetTransferService.selectSysAssetTransferList(sysAssetTransfer);
        ExcelUtil<SysAssetTransferVo> util = new ExcelUtil<SysAssetTransferVo>(SysAssetTransferVo.class);
        util.exportExcel(response, list, "资产调拨数据");
    }

    /**
     * 获取资产调拨详细信息
     */
    @RequiresPermissions("system:transfer:query")
    @GetMapping(value = "/{transferId}")
    public AjaxResult getInfo(@PathVariable("transferId") Long transferId)
    {
        return success(sysAssetTransferService.selectSysAssetTransferByTransferId(transferId));
    }

    /**
     * 新增资产调拨
     */
    @RequiresPermissions("system:transfer:add")
    @Log(title = "资产调拨", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAssetTransfer sysAssetTransfer)
    {
        return toAjax(sysAssetTransferService.insertSysAssetTransfer(sysAssetTransfer));
    }

    /**
     * 修改资产调拨
     */
    @RequiresPermissions("system:transfer:edit")
    @Log(title = "资产调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAssetTransfer sysAssetTransfer)
    {
        return toAjax(sysAssetTransferService.updateSysAssetTransfer(sysAssetTransfer));
    }

    /**
     * 删除资产调拨
     */
    @RequiresPermissions("system:transfer:remove")
    @Log(title = "资产调拨", businessType = BusinessType.DELETE)
	@DeleteMapping("/{transferIds}")
    public AjaxResult remove(@PathVariable Long[] transferIds)
    {
        return toAjax(sysAssetTransferService.deleteSysAssetTransferByTransferIds(transferIds));
    }
}
